<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-8-9
 * Time: 下午 04:07
 */
/**
 * 计算绝对路径
 * @param 当前路径 $cur
 * @param 相对路径 $relative
 */
function getAbsolutePath($cur, $relative)
{
    $cur = str_replace('//', '/', $cur);
    $relative = str_replace('//', '/', $relative);
    $curArr = explode('/', $cur);
    $reArr = explode('/', $relative);
    $curlen = count($curArr);
    $relen = count($reArr);
    $base = $cur;
    if ($reArr[0] == '..') {
        foreach ($reArr as $val) {
            if ($val == '..') {
                $base = dirname($base);
                continue;
            }
            return $base . '/' . str_replace('../', '', $relative);
        }
    } elseif ($reArr[0] == '') {
        return $relative;
    } else {
        if ($reArr[0] == '.') {
            return $base . '/' . str_replace('./', '', $relative);
        }
        return $base . '/' . $relative;
    }
}